<template>
  <div class="dialog-admin">
    <el-dialog
      :visible.sync="dialogVisible"
      :title="field"
      width="800px"
      @close="handleClose"
    >
      <el-form
        ref="ruleForm"
        :model="ruleForm"
        :rules="rules"
        label-width="150px"
        class="dialog-ruleForm"
      >
        <el-form-item label="任务名称:">
          <el-input v-model="ruleForm.name" :readonly="true" />
        </el-form-item>
        <el-form-item label="任务分组:" prop="name">
          <el-input v-model="ruleForm.name" clearable />
        </el-form-item>
        <el-form-item label="调用目标字符串:" prop="name">
          <el-input v-model="ruleForm.name" clearable />
        </el-form-item>
        <el-form-item label="cron表达式:" prop="name">
          <el-input v-model="ruleForm.name" clearable />
        </el-form-item>
        <el-form-item label="执行策略:" prop="name">
          <el-radio-group v-model="radio" size="small">
            <el-radio label="1">立即执行</el-radio>
            <el-radio label="2">执行一次</el-radio>
            <el-radio label="3">放弃执行</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="并发执行:">
          <el-radio-group v-model="radio" size="small">
            <el-radio label="1">允许</el-radio>
            <el-radio label="2">禁止</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="状态:">
          <el-radio-group v-model="radio" size="small">
            <el-radio label="1">正常</el-radio>
            <el-radio label="2">暂停</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注信息:">
          <el-input
            v-model="ruleForm.name"
            type="textarea"
            :autosize="{ minRows: 1, maxRows: 4 }"
            clearable
          />
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="centerDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="centerDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    field: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      ruleForm: {
        name: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入活动名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
      },
      radio: "1",
    };
  },
  computed: {
    dialogVisible: {
      get() {
        return this.value; // 返回父组件通过 v-model 传递的值
      },
      set(val) {
        this.$emit("close", val); // 当 dialogVisible 变化时，通知父组件更新
      },
    },
  },
  methods: {
    handleClose() {
      this.dialogVisible = false; // 关闭弹窗
      this.$emit("close"); // 发送关闭事件给父组件
    },
  },
};
</script>
<style scoped lang="scss">
.dialog-ruleForm {
  width: 80%;
  line-height: 60px;
  margin: 0 auto;

  .el-radio-group {
    margin-left: 10px;
  }
}
</style>
